﻿Imports MySql.Data.MySqlClient

Public Class checkCode
    Dim connString As String = "Server=localhost; User Id=root; Password=; Database=leximoore"
    Dim dr As MySqlDataReader
    Public Function checkOnlineCode()
        Dim code As String = bookedOnlineForm.bookingCodeTxt.Text()

        Using SQLConnection As New MySqlConnection(connString)
            Using sqlCommand As New MySqlCommand()

                With sqlCommand
                    .CommandText = "SELECT confirmation FROM reservation WHERE confirmation LIKE '" + "%" + code + "%" + "'"
                    .Connection = SQLConnection
                    .CommandType = CommandType.Text
                End With
                Try
                    SQLConnection.Open()
                    dr = sqlCommand.ExecuteReader()
                    If dr.HasRows Then
                        Return True
                    Else
                        Return False
                    End If



                Catch ex As MySqlException
                    MessageBox.Show(ex.Message)
                    Console.ReadLine()
                Finally
                    SQLConnection.Close()
                End Try
            End Using
        End Using
    End Function

    Public Function checkCode()
        Dim code As String = checkOutForm.bookingCodeTxt.Text()

        Using SQLConnection As New MySqlConnection(connString)
            Using sqlCommand As New MySqlCommand()

                With sqlCommand
                    .CommandText = "SELECT confirmation FROM reservation WHERE confirmation LIKE '" + "%" + code + "%" + "'"
                    .Connection = SQLConnection
                    .CommandType = CommandType.Text
                End With
                Try
                    SQLConnection.Open()
                    dr = sqlCommand.ExecuteReader()
                    If dr.HasRows Then
                        Return True
                    Else
                        Return False
                    End If



                Catch ex As MySqlException
                    MessageBox.Show(ex.Message)
                    Console.ReadLine()
                Finally
                    SQLConnection.Close()
                End Try
            End Using
        End Using
    End Function

End Class
